package com.ewhale.feitengguest.ui.user.mine.adapter;

import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.ewhale.feitengguest.R;
import com.ewhale.feitengguest.dto.MyTaskDetailDto;
import com.simga.library.adapter.recyclerview.BaseViewHolder;
import com.simga.library.adapter.recyclerview.MutiRecyclerAdapter;

import java.util.List;

import butterknife.BindView;

/**
 * 作者：SimGa
 * 日期：2019/8/20
 * 时间：14:55
 * 包名：com.ewhale.feitengguest.ui.user.mine.adapter
 */
public class ContentAdapter extends MutiRecyclerAdapter<MyTaskDetailDto.ContentExplainDtosBean> {
    private boolean isShow;

    public ContentAdapter(List<MyTaskDetailDto.ContentExplainDtosBean> data, boolean isShow) {
        super(data, R.layout.item_content);
        this.isShow = isShow;
    }

    @Override
    protected BaseViewHolder<MyTaskDetailDto.ContentExplainDtosBean> getViewHolder() {
        return new ViewHolder(view);
    }

    class ViewHolder extends BaseViewHolder<MyTaskDetailDto.ContentExplainDtosBean> {
        @BindView(R.id.tv_content)
        TextView mTvContent;
        @BindView(R.id.et_content)
        EditText mEtContent;

        public ViewHolder(View itemView) {
            super(itemView);
        }

        @Override
        public void build(MyTaskDetailDto.ContentExplainDtosBean object, int position) {
            mTvContent.setText(object.getExplain());
            mEtContent.setText(object.getContent());
            mEtContent.setEnabled(isShow);
            mEtContent.addTextChangedListener(new TextWatcher() {
                @Override
                public void beforeTextChanged(CharSequence s, int start, int count, int after) {
                }
                @Override
                public void onTextChanged(CharSequence s, int start, int before, int count) {
                    object.setContent(s.toString());
                }
                @Override
                public void afterTextChanged(Editable s) {
                }
            });
        }
    }
}
